// TypeScript file
module starlingswf
{
/**
 * swf资源管理类
 */
export class SwfAssetManager
{

    public static hrefValue: string = "";
    private sheets: Object;
    private textures: Object;

    constructor()
    {
        this.sheets = {};
        this.textures = {};    
    }

    public addSpriteSheet(name: string, sheet: egret.SpriteSheet): void
    {
        this.sheets[name] = sheet;
    }

    public addTexture(name: string, texture: egret.Texture): void
    {
        this.textures[name] = texture;
    }
    
    public createBitmap(name: string): egret.Bitmap
    {
        let texture: egret.Texture = this.getTexture(name);
        if (null == texture)
        {
            return null;
        }

        let bitmap: egret.Bitmap = new egret.Bitmap();
        bitmap.texture = texture;
        return bitmap;
    }

    public getTexture(name: string): egret.Texture
    {
        let texture: egret.Texture;
        let sheet: egret.SpriteSheet;
        let key: string;

        for (key in this.sheets)
        {
            sheet = this.sheets[key];
            texture = sheet.getTexture(name);
            if (null != texture)
            {
                break;
            }
        }
        if (null == texture)
        {
            texture = this.textures[name];
        }
        return texture;
    }
}

}//end of module starlingswf